package com.dsr.consts;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author dsr
 * @date 2020-06-21
 **/
@Data
public class Result implements Serializable {
    private boolean flag;
    private Integer code;
    private String message;
    private Object data;

    public Result(boolean flag, Integer code, String message, Object data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result(boolean flag, Integer code, Object data) {
        this.flag = flag;
        this.code = code;
        this.data = data;
    }
    public static Result success(Object data){
        return new Result(true, HttpStatus.OK.value(),data);
    }
    public static Result success(String message, Object data){
        return new Result(true, HttpStatus.OK.value(),message,data);
    }
    public static Result success(String message){
        return new Result(true, HttpStatus.OK.value(),message);
    }
    public static Result error(String message){
        return new Result(false, HttpStatus.INTERNAL_SERVER_ERROR.value(),message);
    }
    public static Result error( Integer code,String message){
        return new Result(false, code,message);
    }
}
